package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.ProductSkuVo;
import com.spzx.product.api.domain.SkuLockVo;
import com.spzx.product.api.domain.SkuPriceVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Description:
 * RemoteProductService的降级策略
 * @author Yanxinhao on 2024/12/25
 */
@Slf4j
@Component //此处单单加一个@Component注解，是无法将本类注册为bean的
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    @Override
    public RemoteProductService create(Throwable cause) {
        return new RemoteProductService() {
            @Override
            public R<ProductSkuVo> getProductSku(Long skuId, String source) {
                log.error("获取商品sku信息失败:{}", cause.getMessage());
                return R.fail("获取商品sku信息失败:" + cause.getMessage());
            }

            @Override
            public R<SkuPriceVo> getSkuPrice(Long skuId, String source) {
                log.error("获取商品sku价格失败:{}", cause.getMessage());
                return R.fail("获取商品sku价格失败:" + cause.getMessage());
            }

            @Override
            public R<List<SkuPriceVo>> getSkuPriceList(List<Long> skuIdList, String source) {
                log.error("批量获取商品sku最新价格信息失败:{}", cause.getMessage());
                return R.fail("批量获取商品sku最新价格信息失败:" + cause.getMessage());
            }

            @Override
            public R<String> checkAndLock(String orderNo, List<SkuLockVo> skuLockVoList, String source) {
                log.error("检查库存并锁定库存失败:{}", cause.getMessage());
                return R.fail("检查库存并锁定库存失败:" + cause.getMessage());
            }


        };
    }
}